<template>
  <div>
      <div class="loading" v-if="loadNum<=100">
        <x-progress :percent="loadNum" :show-cancel="false"></x-progress>
        <label>{{loadNum}}%</label>
      </div>
  </div>
</template>

<script>
  import { XProgress } from 'vux'

  export default {
    data () {
      return {
        loadNum: 0
      }
    },
    components: {
      XProgress
    },
    created(){
      //获取产品信息
      this.$http.get("/transparent/queryTransparent?tid="+this.$base.tid).then(result=>{
        this.$utils.setData("productData",result);
        this.addLoadNum();

        //获取企业信息
        this.$http.get("/farm/node4zs?system_code=XNC&tenantid="+this.$base.tenantid+"&this_tenantid="+result.useDefPara.tenantId).then(result2=>{
          this.$utils.setData("enterpriseData",result2);
          this.addLoadNum();
        })

      })

      //获取透明供应信息
      this.$http.get("/transparent/getsupplyinfo?tid="+this.$base.tid).then(result=>{
        this.$utils.setData("supplyData",result);
        this.addLoadNum();

        //获取农事活动信息
        this.$http.get("/production/getActiveByCommodityId?commodityId="+result.useDefPara.productionPlanId).then(result2=>{
          this.$utils.setData("ActiveData",result2);
          this.addLoadNum();
        })

      })

      //获取人员
      this.$http.get("/tenant/getListByRootId?rootId="+this.$base.tenantid).then(result=>{
        this.$utils.setData("personData",result);
        this.addLoadNum();
      })


    },
    methods: {
      addLoadNum(){
        var count = Math.ceil(100/5) ;
        var loadNum = this.loadNum;
        loadNum = loadNum + count;
        if(loadNum>=100){
          loadNum = 100;
          this.loadNum = loadNum;
          this.$utils.setData("loadDone",true);
          var beforeLoginUrl = sessionStorage.getItem("beforeLoginUrl");

          if(beforeLoginUrl){
            this.$router.replace(beforeLoginUrl)
          }else{
            this.$router.replace("/")
          }
        }else {
          this.loadNum = loadNum
        }

      }
    }
  }
</script>
<style scoped>
  .loading{
    position: fixed;
    top: 40vh;
    padding: 0 30vw;
    color: #70aa2f;
    width: 40vw;
    text-align: center;
  }
</style>
